<%@ page contentType="text/html;charset=ISO-8859-1" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.google.gson.Gson" %>
<%@ page import="com.google.gson.GsonBuilder" %>
<%@ page import="com.eventosgasteiz.server.bbdd.Event" %>
<%@ page import="com.eventosgasteiz.server.bbdd.PMF" %>

<html>
  <body>
<%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + Event.class.getName();
    List<Event> eventos = (List<Event>) pm.newQuery(query).execute();
    if (eventos.isEmpty()) {
%>
<p>No hay eventos.</p>
<%
    } else {
%>
<center>
<h1>LISTADO DE EVENTOS</h1>
</center>
<table border="1" width="90%" align="center">
<tr align="center" style="background: #9cf">
<td>ID</td><td>NOMBRE</td><td>FECHA INICIO</td><td>FECHA FIN</td><td></td><td></td>
</tr>
<%
    	Gson gson = new GsonBuilder().disableHtmlEscaping().create();
        for (Event e : eventos) {
%>
<tr>
<td><%= e.getId() %></td><td><%= e.getName() %></td><td><%= e.getFecha_inicio() %></td><td><%= e.getFecha_fin() %></td>
<td align="center">
<% if (e.getOption()=='U' || e.getOption()=='I') { %>
<a href="/borrarEvento?option=D&id=<%=e.getId().getId()%>">Borrar</a>
<% } else { %>
<a href="/borrarEvento?option=U&id=<%=e.getId().getId()%>">Recuperar</a>
<% } %>
</td>
<td align="center"><a href="/EditarEvento.jsp?id=<%=e.getId().getId()%>">Editar</a></td>
</tr>
<%
        }
%>
</table>
<%
    }
    pm.close();
%>
  </body>
</html>